package com.lj.service.Impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lj.mapper.StaffljMapper;
import com.lj.pojo.Clientlj;
import com.lj.pojo.Stafflj;
import com.lj.pojo.StaffljExample;
import com.lj.service.StaffService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StaffServiceImpl implements StaffService {
    @Autowired
    StaffljMapper staffljMapper;
    @Override
    public Stafflj login(String name, String pwd) {
        StaffljExample example=new StaffljExample();
        example.createCriteria().andStaffIdEqualTo(name);
        List<Stafflj> list=staffljMapper.selectByExample(example);
        if(list.size()>0){
            Stafflj stafflj=list.get(0);
            if(stafflj.getStaffPassword().equals(pwd)){
                return stafflj;
            }
        }
        return null;
    }
    @Override
    public PageInfo selectStaff(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        StaffljExample example=new StaffljExample();
        example.setOrderByClause("staff_id desc");
        List<Stafflj> list=staffljMapper.selectByExample(example);
        PageInfo<Stafflj> pageInfo=new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public int insertStaff(Stafflj stafflj) {
        return staffljMapper.insert(stafflj);
    }

    @Override
    public int delete(String id) {
        return staffljMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int update(Stafflj stafflj) {
       return staffljMapper.updateByPrimaryKey(stafflj);
    }

    @Override
    public Stafflj getById(String id) {
        StaffljExample example=new StaffljExample();
        example.createCriteria().andStaffIdEqualTo(id);
        List<Stafflj> list=staffljMapper.selectByExample(example);
        if(list.size()>0){
            return list.get(0);
        }
        return null;
    }
}
